/**
 * [905] 按奇偶排序数组
 *
 * @format
 * @lc app=leetcode.cn id=905 lang=javascript
 */

// @lc code=start
/**
 * @param {number[]} nums
 * @return {number[]}
 */
var sortArrayByParity = function (nums) {
    let [left, right] = [0, nums.length - 1]
    while (left < right) {
        if (nums[left] % 2 != 0) {
            nums[left] += nums[right]
            nums[right] = nums[left] - nums[right]
            nums[left] -= nums[right]
            right--
        } else {
            left++
        }
    }
    return nums
}
// @lc code=end
